
/* ************************************************************************************* 
 * CREATED BY:          MYGENERATION
 * CREATED DATE:        2/7/2009
 * PROJECT:             MCWEBSITE
 * PURPOSE:             LinksDAL class
 * MODIFIED BY:         None
 * MODIFIED DATE:       None
 * MODIFIED REASON:     None
 * NOTES:               None
 **************************************************************************************/
 
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Web.Configuration;
using MCWEBSITE.ENTITY;

namespace MCWEBSITE.DAL
{
    public class LinksDAL
    {
        #region  Properties
		 
		public static string FIELD_LINKCODE = "LinkCode";  
		public static string FIELD_LINKNAME = "LinkName";  
		public static string FIELD_PAGEID = "PageId";  
		public static string FIELD_LANGUAGECODE = "LanguageCode";  
		public static string FIELD_LINKTYPEID = "LinkTypeId";  
		public static string FIELD_QUERYSTRING1 = "QueryString1";  
		public static string FIELD_QUERYATTRIBUTE1 = "QueryAttribute1";  
		public static string FIELD_QUERYSTRING2 = "QueryString2";  
		public static string FIELD_QUERYATTRIBUTE2 = "QueryAttribute2";  
		public static string FIELD_QUERYSTRING3 = "QueryString3";  
		public static string FIELD_QUERYATTRIBUTE3 = "QueryAttribute3";  
		public static string FIELD_QUERYSTRING4 = "QueryString4";  
		public static string FIELD_QUERYATTRIBUTE4 = "QueryAttribute4";  
		public static string FIELD_QUERYSTRING5 = "QueryString5";  
		public static string FIELD_QUERYATTRIBUTE5 = "QueryAttribute5"; 
		public static string ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ContentConnectionString"].ToString();

        #endregion

        #region Protected methods

        /// <summary>
        /// Select entity of Links
        /// </summary>
        /// <param name="LinkCode">Primary Keys</param>
        /// <returns>Collection of LinksInfo</returns>
        public static LinksInfo SelectOne(string LinkCode)
        {
            LinksInfo _LinksInfo = new LinksInfo();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_conf_LinksSelectOne", LinkCode);
                if (dr.Read())
                    setLinksInfo(dr, ref _LinksInfo);
                return _LinksInfo;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select all Links
        /// </summary>
        /// <returns>Collection of LinksInfo</returns>
        public static List<LinksInfo> SelectAll()
        {
            List<LinksInfo> lstLinks = new List<LinksInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_conf_LinksSelectAll");
                setListLinksInfo(ref dr, ref lstLinks);
                return lstLinks;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select
        /// </summary>
        /// <param name="Linksnfo">Modify this method adapting your need</param>
        /// <returns>Collection of LinksInfo</returns>
        public static List<LinksInfo> SelectFilters()
        {
            string criterias = string.Empty;
            List<LinksInfo> lstLinks = new List<LinksInfo>();
            SqlDataReader dr = null;
            try 
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_conf_LinksSelectByFilters");
                setListLinksInfo(ref dr, ref lstLinks);
                return lstLinks;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Insert Links
        /// </summary>
        /// <param name="LinksInfo">Entity of Links</param>
        /// <returns>error code</returns>
        public static int Insert(LinksInfo _LinksInfo)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_conf_LinksInsert" 
											, _LinksInfo.LinkName
											, _LinksInfo.PageId
											, _LinksInfo.LanguageCode
											, _LinksInfo.LinkTypeId
											, _LinksInfo.QueryString1
											, _LinksInfo.QueryAttribute1
											, _LinksInfo.QueryString2
											, _LinksInfo.QueryAttribute2
											, _LinksInfo.QueryString3
											, _LinksInfo.QueryAttribute3
											, _LinksInfo.QueryString4
											, _LinksInfo.QueryAttribute4
											, _LinksInfo.QueryString5
											, _LinksInfo.QueryAttribute5
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        
        /// <summary>
        /// Update Links
        /// </summary>
        /// <param name="LinksInfo">Entity of Links</param>
        /// <returns>error code</returns>
        public static int Update(LinksInfo _LinksInfo)
        {            
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_conf_LinksUpdate"
											, _LinksInfo.LinkCode
											, _LinksInfo.LinkName
											, _LinksInfo.PageId
											, _LinksInfo.LanguageCode
											, _LinksInfo.LinkTypeId
											, _LinksInfo.QueryString1
											, _LinksInfo.QueryAttribute1
											, _LinksInfo.QueryString2
											, _LinksInfo.QueryAttribute2
											, _LinksInfo.QueryString3
											, _LinksInfo.QueryAttribute3
											, _LinksInfo.QueryString4
											, _LinksInfo.QueryAttribute4
											, _LinksInfo.QueryString5
											, _LinksInfo.QueryAttribute5
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// Delete SchoolAdmin
        /// </summary>
        /// <param name="LinkCode">Primary Key</param>
        /// <returns>error code</returns>
        public static int Delete(string LinkCode)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_conf_LinksDelete", LinkCode);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        #endregion

        #region "Utilities method"
		
        private static void setListLinksInfo(ref SqlDataReader dr, ref List<LinksInfo> lstLinks)
        {
            LinksInfo _LinksInfo = null;
            while (dr.Read())
            {
                _LinksInfo = new LinksInfo();
                setLinksInfo(dr, ref _LinksInfo);
                lstLinks.Add(_LinksInfo);
            }
        }

        private static void setLinksInfo(SqlDataReader dr, ref LinksInfo _LinksInfo)
        {
			_LinksInfo.LinkCode = dr[LinksDAL.FIELD_LINKCODE] != DBNull.Value ? Convert.ToString(dr[LinksDAL.FIELD_LINKCODE]) : string.Empty;
			_LinksInfo.LinkName = dr[LinksDAL.FIELD_LINKNAME] != DBNull.Value ? Convert.ToString(dr[LinksDAL.FIELD_LINKNAME]) : string.Empty;
			_LinksInfo.PageId = dr[LinksDAL.FIELD_PAGEID] != DBNull.Value ? Convert.ToInt32(dr[LinksDAL.FIELD_PAGEID]) : 0;
			_LinksInfo.LanguageCode = dr[LinksDAL.FIELD_LANGUAGECODE] != DBNull.Value ? Convert.ToString(dr[LinksDAL.FIELD_LANGUAGECODE]) : string.Empty;
			_LinksInfo.LinkTypeId = dr[LinksDAL.FIELD_LINKTYPEID] != DBNull.Value ? Convert.ToInt32(dr[LinksDAL.FIELD_LINKTYPEID]) : 0;
			_LinksInfo.QueryString1 = dr[LinksDAL.FIELD_QUERYSTRING1] != DBNull.Value ? Convert.ToString(dr[LinksDAL.FIELD_QUERYSTRING1]) : string.Empty;
			_LinksInfo.QueryAttribute1 = dr[LinksDAL.FIELD_QUERYATTRIBUTE1] != DBNull.Value ? Convert.ToString(dr[LinksDAL.FIELD_QUERYATTRIBUTE1]) : string.Empty;
			_LinksInfo.QueryString2 = dr[LinksDAL.FIELD_QUERYSTRING2] != DBNull.Value ? Convert.ToString(dr[LinksDAL.FIELD_QUERYSTRING2]) : string.Empty;
			_LinksInfo.QueryAttribute2 = dr[LinksDAL.FIELD_QUERYATTRIBUTE2] != DBNull.Value ? Convert.ToString(dr[LinksDAL.FIELD_QUERYATTRIBUTE2]) : string.Empty;
			_LinksInfo.QueryString3 = dr[LinksDAL.FIELD_QUERYSTRING3] != DBNull.Value ? Convert.ToString(dr[LinksDAL.FIELD_QUERYSTRING3]) : string.Empty;
			_LinksInfo.QueryAttribute3 = dr[LinksDAL.FIELD_QUERYATTRIBUTE3] != DBNull.Value ? Convert.ToString(dr[LinksDAL.FIELD_QUERYATTRIBUTE3]) : string.Empty;
			_LinksInfo.QueryString4 = dr[LinksDAL.FIELD_QUERYSTRING4] != DBNull.Value ? Convert.ToString(dr[LinksDAL.FIELD_QUERYSTRING4]) : string.Empty;
			_LinksInfo.QueryAttribute4 = dr[LinksDAL.FIELD_QUERYATTRIBUTE4] != DBNull.Value ? Convert.ToString(dr[LinksDAL.FIELD_QUERYATTRIBUTE4]) : string.Empty;
			_LinksInfo.QueryString5 = dr[LinksDAL.FIELD_QUERYSTRING5] != DBNull.Value ? Convert.ToString(dr[LinksDAL.FIELD_QUERYSTRING5]) : string.Empty;
			_LinksInfo.QueryAttribute5 = dr[LinksDAL.FIELD_QUERYATTRIBUTE5] != DBNull.Value ? Convert.ToString(dr[LinksDAL.FIELD_QUERYATTRIBUTE5]) : string.Empty;
			                        
        }
        #endregion Methods

        #region Private Members

        private static string TABLE_NAME = "[conf_Links]";

        #endregion
    }
}

		